

********************************
* Standard Stata Configuration *
********************************
clear all
set mem 999m
capture log close
set logtype text
cap cd "C:/Users/Jordan.Becker/Desktop/GD/1_Research"
cap cd "G:\My Drive\1_Research"
cap cd "C:\Users\jordan.becker\My Drive\1_Research"
set more off


********************
* Analyze the Data *
********************
use "dta\2021_master", clear

sort ccode year
xtset ccode year
keep if nato_or_eu_year_dummy==1
sort countryname year

***************************************
*FIGURE 1: DUMBELL CHART ALL NATO & EU*
***************************************
preserve
*Generate 2014 and 2020 equipment and milex*
bysort ccode: gen equipment_gdp_2014=equipment_gdp if year==2014
bysort ccode: gen equipment_gdp_2020=equipment_gdp if year==2020
bysort ccode: gen milburden_2014=milburden if year==2014
bysort ccode: gen milburden_2020=milburden if year==2020

bysort ccode (equipment_gdp_2014): replace equipment_gdp_2014 = equipment_gdp_2014[1]
bysort ccode (equipment_gdp_2020): replace equipment_gdp_2020 = equipment_gdp_2020[1]

bysort ccode (milburden_2014): replace milburden_2014 = milburden_2014[1]
bysort ccode (milburden_2020): replace milburden_2020 = milburden_2020[1]


keep if year==2020 & equipment_gdp_2020 !=. 
 
 * Preparing Y-axis
 generate srno = _n * 3
 labmask srno, values(countryname)
 

 
 colorpalette w3, nograph
 twoway  (rspike equipment_gdp_2014 equipment_gdp_2020 srno, horizontal lcolor("`r(p6)'*0.4")) ///
   (scatter srno equipment_gdp_2014, mcolor("`r(p6)'*0.4")) ///
   (scatter srno equipment_gdp_2020, mcolor("`r(p6)'")) ///
   if equipment_gdp_2014!=., /// 
  ylabel(3(3)105, valuelabel angle(horizontal) labsize(2)) ///
   legend(order(3 "2020" 2 "2014") pos(11) row(1) size(2)) ///
   ytitle("") ///
   title("{bf}Dumbbell Plot", pos(11) size(2.75)) ///
   subtitle("Change in Equipment/GDP By Country: 2014 vs. 2020", pos(11) size(2)) ///
   scheme(white_tableau)
      graph save nordics/output/CSPfigure1_equipment_dumbellchart.gph, replace
	  graph export nordics/figures/CSPfigure1_equipment_dumbellchart.tif, replace
   
   *Nordics Only*
   
   keep if nordic_dummy==1 & countryname!="Iceland"
    colorpalette w3, nograph
 twoway  (rspike equipment_gdp_2014 equipment_gdp_2020 srno, horizontal lcolor("`r(p6)'*0.4")) ///
   (scatter srno equipment_gdp_2014, mcolor("`r(p6)'*0.4")) ///
   (scatter srno equipment_gdp_2020, mcolor("`r(p6)'")) ///
   , /// 
  ylabel(93(3)102, valuelabel angle(horizontal) labsize(2)) ///
   legend(order(3 "2020" 2 "2014") pos(11) row(1) size(2)) ///
   ytitle("") ///
   title("{bf}Dumbbell Plot (Nordic Countries)", pos(11) size(2.75)) ///
   subtitle("Change in Equipment/GDP By Country: 2014 vs. 2020", pos(11) size(2)) ///
   scheme(white_tableau)
   
       colorpalette w3, nograph
 twoway  (rspike milburden_2014 milburden_2020 srno, horizontal lcolor("`r(p6)'*0.4")) ///
   (scatter srno milburden_2014, mcolor("`r(p6)'*0.4")) ///
   (scatter srno milburden_2020, mcolor("`r(p6)'")) ///
   , /// 
  ylabel(93(3)102, valuelabel angle(horizontal) labsize(2)) ///
   legend(order(3 "2020" 2 "2014") pos(11) row(1) size(2)) ///
   ytitle("") ///
   title("{bf}Dumbbell Plot (Nordic Countries)", pos(11) size(2.75)) ///
   subtitle("Change in Equipment/GDP By Country: 2014 vs. 2020", pos(11) size(2)) ///
   scheme(white_tableau)
   graph save nordics/output/figureTBD_milburden_dumbellchart.gph, replace
   graph export nordics/figures/figureTBD_milburden_dumbellchart.tif, replace
   
   restore
   
***********************************************   
*TABLE 1: SUMMARY STATS (embedded in Table 3  *
***********************************************

******************************************************
*TABLE 1A: Pairwise Correlations Use Below for Sample*
******************************************************
pwcorr milburden equipment_gdp year ln_gdp russia_spatial spatial_spillins pv_est sl_uem_totl_zs percent_n shaming_rochelle, star(5)


   
**********************************************************************   
*FIGURE 2: TIME SERIES TRANSATLANTIC BURDEN SHARING - parallel trends*
**********************************************************************

#delimit;
twoway(tsline nonusnato_milburden if year >=2010 & year <=2020, lcolor(navy))
	  (tsline nonnato_eu_milburden if year >=2010 & year <=2020, lcolor(green))
	  if year>=2005, scheme(white_w3d) xline (2014)
	  xtitle("") xlab(2010(1)2020, labsize(small) angle(45)) ylab(.75(.1)1.75, 
	  labsize(small)) ytitle("Defense Spending (% GDP)", size(medium) margin(medium))
	  legend(rows(2) size(medium) label(1 NATO Members excluding United States)  label (2 Non-NATO EU Member States));
graph save nordics\output\figure2a_paralleltrends.gph, replace;
graph export nordics\Figures\figure2a_paralleltrends_milburden.tif, replace;

twoway(tsline nonusnato_equipment if year >=2010 & year <=2020, lcolor(navy))
	  (tsline nonnato_eu_equipment if year >=2010 & year <=2020, lcolor(green))
	  if year>=2005, scheme(white_w3d) xline (2014)
	  xtitle("") xlab(2010(1)2020, labsize(small) angle(45)) ylab(.1(.05).4, 
	  labsize(small)) ytitle("Equipment Spending (% GDP)", size(medium) margin(medium))
	  legend(rows(2) size(medium) label(1 NATO Members excluding United States)  label (2 Non-NATO EU Member States));
graph save nordics\output\figure2b_paralleltrends.gph, replace;
graph export nordics\Figures\figure2b_paralleltrends_equipment.tif, replace;

#delimit;
grc1leg nordics/output/figure2a_paralleltrends.gph nordics/output/figure2b_paralleltrends.gph, 
title("Parallel Trends: Milex/GDP, Equipment/GDP", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("Burden-Sharing Metrics", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics/output/figure2_parallelltrends, replace;
graph export nordics/figures/figure2_parallelltrends.tif, replace;

*Tests for Parallel Trends*
#delimit;
gen walespledgedummy=0;
replace walespledgedummy=1 if year>2014 & nato_year_dummy==1;
xtdidregress (equipment_gdp) (walespledgedummy) if year>=2009 & nato_or_eu_dummy==1 & countryname!="Montenegro" & countryname!="Iceland" & countryname!="Macedonia", group(ccode) time(year);

estat ptrends;

estat granger;


xtdidregress (equipment_gdp) (walespledgedummy) if year>=2009 & nato_or_eu_dummy==1 & countryname!="Montenegro" & countryname!="Iceland" & countryname!="Macedonia", group(ccode) time(year) wildbootstrap(rseed(111));


**************************************************************
*FIGURE 3: TIME SERIES TRANSATLANTIC Milburden, and Equipment*
**************************************************************

#delimit;



twoway(tsline milburden if countryname=="Denmark", lcolor(navy))
	  (tsline milburden if countryname=="Finland", lcolor(green))
	  (tsline milburden if countryname=="Norway", lcolor(black))
	  (tsline milburden if countryname=="Sweden", lcolor(maroon))if year>=2005 & year<=2020,  scheme(white_w3d) xline(2014)
	  xtitle("") xlab(2005(1)2020, labsize(tiny) angle(45)) ylab(1(.2)2, 
	  labsize(small)) ytitle("Milex (% GDP)", size(small) margin(medium))
	  legend(rows(2) size(tiny) label(1 Denmark)  label (2 Finland) label(3 Norway) label(4 Sweden));
graph save nordics/output\figure3a_milburdents.gph, replace;
graph export nordics/figures\figure3a_milburdents.tif, replace;

twoway(tsline equipment_gdp if countryname=="Denmark", lcolor(navy))
	  (tsline equipment_gdp if countryname=="Finland", lcolor(green))
	  (tsline equipment_gdp if countryname=="Norway", lcolor(black))
	  (tsline equipment_gdp if countryname=="Sweden", lcolor(maroon))if year>=2005 & year<=2020, scheme(white_w3d)xline(2014)
	  xtitle("") xlab(2005(1)2020, labsize(tiny) angle(45)) ylab(0(.1).6, 
	  labsize(small)) ytitle("Equipment (% GDP)", size(small) margin(medium))
	  legend(rows(2) size(tiny) label(1 Denmark)  label (2 Finland) label(3 Norway) label(4 Sweden));
graph save nordics/output\figure3b_equpmentts.gph, replace;
graph export nordics/figures\figure3b_equpmentts.tif, replace;

#delimit;
grc1leg nordics/output/figure3a_milburdents.gph nordics/output/figure3b_equpmentts.gph, 
title("Parallel Trends: Milex/GDP, Equipment/GDP", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("Burden-Sharing Metrics", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics/output/figure3_paralleltrendsnordicsonly, replace;
graph export nordics/figures/figure3_paralleltrendsnordicsonly.tif, replace;


*Tests for Parallel Trends*
#delimit;
preserve;
xtdidregress (equipment_gdp) (walespledgedummy) if year>=2009 & nordic_dummy==1, group(ccode) time(year);

estat ptrends;

estat granger;


xtdidregress (equipment_gdp) (walespledgedummy) if year>=2009 & nordic_dummy==1, group(ccode) time(year) wildbootstrap(rseed(111));

#delimit cr;
restore

********************************
*FIGURE 4: SLOPE CHART, NORDICS*
********************************


*Generate 2014 and 2020 equipment and milex*
#delimit cr;
preserve

bysort ccode: gen equipment_gdp_2014=equipment_gdp if year==2014
bysort ccode: gen equipment_gdp_2020=equipment_gdp if year==2020
bysort ccode: gen milburden_2014=milburden if year==2014
bysort ccode: gen milburden_2020=milburden if year==2020

bysort ccode (equipment_gdp_2014): replace equipment_gdp_2014 = equipment_gdp_2014[1]
bysort ccode (equipment_gdp_2020): replace equipment_gdp_2020 = equipment_gdp_2020[1]

bysort ccode (milburden_2014): replace milburden_2014 = milburden_2014[1]
bysort ccode (milburden_2020): replace milburden_2020 = milburden_2020[1]
 
* Checking which value is lower than previous data value
#delimit cr;
 generate negative_equipment = (equipment_gdp_2020 < equipment_gdp_2014)
 generate negative_milburden = (milburden_2020 < milburden_2014)

 
 generate labequipment2014 = countryname + ", " + string((equipment_gdp2014))
 generate labequipment2020 = countryname + ", " + string((equipment_gdp_2020))
 
 generate labmilburden2014 = countryname + ", " + string((milburden2014))
 generate labmilburden2020 = countryname + ", " + string((milburden_2020))
 
 generate country1 = 1
 generate country2 = 2
 
 *plot*
#delimit cr;

 keep if nordic_dummy==1
  colorpalette w3, nograph
 twoway  (pcspike equipment_gdp_2014 country1 equipment_gdp_2020 country2 if negative_equipment == 0, legend(off) lcolor("`r(p11)'")) ///
   (pcspike  equipment_gdp_2014 country1 equipment_gdp_2020 country2 if negative_equipment == 1, legend(off) lcolor("`r(p1)'")) ///
   (scatter equipment_gdp_2014 country1, ms(i) mlabposition(9) mlabel(labequipment2014)) ///
   (scatter equipment_gdp_2020 country2, ms(i) mlabposition(3) mlabel(labequipment2020)) ///
   (scatteri .65 1 "{bf}Year 2014", ms(i) mlabpos(9)) ///
   (scatteri .65 2 "{bf}Year 2020", ms(i) mlabpos(3)) ///   
   , ///
   ylabel(0(.1).6, labsize(2) nogrid) ///
   ytitle("Equipment/GDP", size(2) orient(horizontal)) ///
   yscale(range(0 .6)) ///
   xlabel(1(1)2) ///
   xscale(off) ///
   xtitle("") ///
   xscale(range(.5 1)) ///
   aspect(1.3) ///
   title("{bf}Slope Chart", pos(11) size(2.75)) ///
   subtitle("Equipment/GDP: 2014 Vs. 2020" " ", pos(11) size(2)) ///
   graphregion(margin(r=25)) ///
   scheme(white_w3d)
   graph save nordics/output/figure4a_equipment_slopechart.gph, replace
   graph export nordics/figures/figure4a_equipment_slopechart.tif, replace
   
   
   restore
   
   
   
   *Generate 2008 and 2014 equipment and milex*
#delimit cr;
preserve

bysort ccode: gen equipment_gdp_2008=equipment_gdp if year==2008
bysort ccode: gen equipment_gdp_2014=equipment_gdp if year==2014
bysort ccode: gen milburden_2008=milburden if year==2008
bysort ccode: gen milburden_2014=milburden if year==2014

bysort ccode (equipment_gdp_2008): replace equipment_gdp_2008 = equipment_gdp_2008[1]
bysort ccode (equipment_gdp_2014): replace equipment_gdp_2014 = equipment_gdp_2014[1]

bysort ccode (milburden_2008): replace milburden_2008 = milburden_2008[1]
bysort ccode (milburden_2014): replace milburden_2014 = milburden_2014[1]
 
* Checking which value is lower than previous data value
#delimit cr;
 generate negative_equipment = (equipment_gdp_2014 < equipment_gdp_2008)
 generate negative_milburden = (milburden_2014 < milburden_2008)

 
 generate labequipment2008 = countryname + ", " + string((equipment_gdp_2008))
 generate labequipment2014 = countryname + ", " + string((equipment_gdp_2014))
 
 generate labmilburden2008 = countryname + ", " + string((milburden_2008))
 generate labmilburden2014 = countryname + ", " + string((milburden_2014))
 
 generate country1 = 1
 generate country2 = 2
 
 *plot*
#delimit cr;

 keep if nordic_dummy==1
  colorpalette w3, nograph
 twoway  (pcspike equipment_gdp_2008 country1 equipment_gdp_2014 country2 if negative_equipment == 0, legend(off) lcolor("`r(p11)'")) ///
   (pcspike  equipment_gdp_2008 country1 equipment_gdp_2014 country2 if negative_equipment == 1, legend(off) lcolor("`r(p1)'")) ///
   (scatter equipment_gdp_2008 country1, ms(i) mlabposition(9) mlabel(labequipment2008)) ///
   (scatter equipment_gdp_2014 country2, ms(i) mlabposition(3) mlabel(labequipment2014)) ///
   (scatteri .65 1 "{bf}Year 2008", ms(i) mlabpos(9)) ///
   (scatteri .65 2 "{bf}Year 2014", ms(i) mlabpos(3)) ///   
   , ///
   ylabel(0(.1).6, labsize(2) nogrid) ///
   ytitle("Equipment/GDP", size(2) orient(horizontal)) ///
   yscale(range(0 .6)) ///
   xlabel(1(1)2) ///
   xscale(off) ///
   xtitle("") ///
   xscale(range(.5 1)) ///
   aspect(1.3) ///
   title("{bf}Slope Chart", pos(11) size(2.75)) ///
   subtitle("Equipment/GDP: 2008 Vs. 2014" " ", pos(11) size(2)) ///
   graphregion(margin(r=25)) ///
   scheme(white_w3d)
   graph save nordics/output/figure4b_equipment_slopechart.gph, replace
   graph export nordics/figures/figure4b_equipment_slopechart.tif, replace
   
   
   #delimit;
graph combine nordics/output/figure4a_equipment_slopechart.gph nordics/output/figure4b_equipment_slopechart.gph, 
title("Parallel Trends: Equipment/GDP", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("Nordic States, Pre- and Post-Wales Pledge", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics/output/figure4_paralleltrendsnordicsonly, replace;
graph export nordics/figures/figure4_paralleltrendsnordicsonly.tif, replace;


restore;
   
#delimit cr;

 ***************************************
 *TABLE 2 NORDIC STATES AS MOST SIMILAR*
 ***************************************
 #delimit cr
 *************************************************
 *TABLE 3: GDD ANALYSIS (2009-2014 VS. 2015-2020)*
 *************************************************
 #delimit cr
 sort ccode year
xtset ccode year

drop  time time2 time3 time4

*create post-wales time dummy* 
gen time = (year>=2015) & !missing(year)

*generate nato treatment dummy*
gen treated = (nato_year_dummy==1) & !missing(nato_year_dummy)

*interaction between time and treatment*
gen did = time*treated

*replace fri missing with zero for Norway*
replace fri=0 if fri==. & countryname=="Norway"

*Summary Stats*

quietly xtreg equipment_gdp did i.year if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020 & countryname!="Macedonia", fe robust cluster(ccode)

fsum milburden equipment_gdp did year ln_gdp russia_spatial spatial_spillins pv_est sl_uem_totl_zs if e(sample)==1, label

*Pairwise Correlations*
pwcorr milburden equipment_gdp  nato_year_dummy year ln_gdp russia_spatial spatial_spillins pv_est sl_uem_totl_zs if e(sample)==1, star(1)




*Model 1 - Equipment Bivariate*
quietly xtreg equipment_gdp did i.year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, fe robust cluster(ccode)
xtreg equipment_gdp did i.year if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020 & e(sample)==1, fe robust cluster(ccode)
vif, uncentered
outreg2 using "nordics/output/nordicsgeneralizeddid.xls", ctit(Equipment/GDP, Bivariate) label addtext(Fixed Effects, Two-Way) bdec(3) cdec(3) pdec(3) tdec(3) rdec(3) replace
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Model 2 - Equipment Joint Product - Strategic Excludability Included in Year FE*
xtreg equipment_gdp did i.year l.ln_gdp  if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, fe robust cluster(ccode)
vif, uncentered
outreg2 using "nordics/output/nordicsgeneralizeddid.xls", ctit(Equipment/GDP, Joint Product) label addtext(Fixed Effects, Two-Way) bdec(3) cdec(3) pdec(3) tdec(3) rdec(3) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Model 3 - Equipment Threat*
xtreg equipment_gdp did i.year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, fe robust cluster(ccode)
vif, uncentered
outreg2 using "nordics/output/nordicsgeneralizeddid.xls", ctit(Equipment/GDP, Threat) label addtext(Fixed Effects, Two-Way) bdec(3) cdec(3) pdec(3) tdec(3) rdec(3) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Model 4 - Equipment UEM*
xtreg equipment_gdp did i.year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs percent_n if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, fe robust cluster(ccode)
vif, uncentered
outreg2 using "nordics/output/nordicsgeneralizeddid.xls", ctit(Equipment/GDP, Domestic PE) label addtext(Fixed Effects, Two-Way) bdec(3) cdec(3) pdec(3) tdec(3) rdec(3) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)


*Model 5 - Milburden FullSpec* 
quietly xtreg equipment_gdp did i.year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, fe robust cluster(ccode)
xtreg milburden did i.year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs percent_n if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020 & e(sample)==1, fe robust cluster(ccode)
vif, uncentered
outreg2 using "nordics/output/nordicsgeneralizeddid.xls", ctit(Milex/GDP, FullSpec) label addtext(Fixed Effects, Two-Way) bdec(3) cdec(3) pdec(3) tdec(3) rdec(3) append


tabstat year if e(sample)==1, statistics(min max) by(countryname)

interflex equipment_gdp treated time ln_gdp russia_spatial spatial_spillins pv_est sl_uem_totl_zs if nato_or_eu_year_dummy==1 & ccode!=2 & year>=2009 & year<=2020, type(linear) ylabel ("Equipment Spending/GDP") dlabel ("Wales Pledge") xlabel ("Time")
graph save nordics/output/table3_interflex, replace


********************************************************
*TABLE 4: STANDARD DD ANALYSIS (2009-2014 VS 2015-2020)*
********************************************************

preserve
keep if countryname!="Iceland" 
*Model 1 - Milburden All*
xtreg milburden time treated did l.ln_gdp  l.spatial_spillins  if nato_or_eu_year_dummy==1 & ccode!=2 & year >=2009 & year<=2020,  r cluster(ccode)
outreg2 using "nordics/output/nordicsdid2020.xls", ctitle (Full Sample, Milex/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) replace
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Model 2 - Equipment All*
xtreg equipment_gdp time treated did l.ln_gdp  l.spatial_spillins  if nato_or_eu_year_dummy==1 & ccode!=2 & year >=2009 & year<=2020,  r cluster(ccode)
outreg2 using "nordics/output/nordicsdid2020.xls", ctitle (Full Sample, Equipment/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)


*Model 3 - Milburden Nordics*
xtreg milburden time treated did l.ln_gdp  l.spatial_spillins  if year >=2009 & year<=2020 & nordic_dummy==1,  
outreg2 using "nordics/output/nordicsdid2020.xls", ctitle (Nordics Only, Milex/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Model 4 - Equipment Nordics*
xtreg equipment_gdp time treated did l.ln_gdp  l.spatial_spillins  if year >=2009 & year<=2020 & nordic_dummy==1, r cluster(ccode)
outreg2 using "nordics/output/nordicsdid2020.xls", ctitle (Nordics Only, Equipment/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) append
tabstat year if e(sample)==1, statistics(min max) by(countryname)

*Mean Comparisons*
tabstat milburden  equipment_gdp if e(sample)==1 & year<=2014, statistics(mean) by(countryname)
tabstat milburden  equipment_gdp if e(sample)==1 & year>=2015, statistics(mean) by(countryname)
restore


**************************************
*FIGURE 5: STANDARD DD, EQUIPMENT/GDP*
**************************************


*DiD Graphs Comparing Equipment/GDP in All Members and just Nordics*


reg equipment_gdp time treated did if nato_or_eu_year_dummy==1 & ccode!=2 & year >=2009 & year<=2020 & countryname!="Iceland" & countryname!="Montenegro", r cluster(ccode)
iegraph time treated did, ytitle("") basictitle("A: Equipment (% GDP, Full Sample)")
graph save nordics/output/figure4a_equipmentDID_all.gph, replace

reg equipment_gdp time treated did if nato_or_eu_year_dummy==1 & ccode!=2 & year >=2009 & year<=2020 & nordic_dummy==1, r cluster(ccode)
iegraph time treated did, ytitle("") basictitle("B: Equipment(% GDP, Nordics)")
graph save nordics/output/figure4b_equipmentDID_nordics.gph, replace

#delimit;
grc1leg nordics/output/figure4a_equipmentDID_all.gph nordics/output/figure4b_equipmentDID_nordics.gph, 
title("Diff-in-Diff: Equipment/GDP, Full Sample & Nordics Only", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("2009-2014 vs. 2015-2020", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics/output/figure4_DID, replace;
graph export nordics/figures/figure4_DID.tif, replace;


*Table TBD: OLS Regressions*
xtreg equipment_gdp year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs, fe
outreg2 using "nordics/output/nordicsols.xls", ctitle (Full Sample OLS, Equipment/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) replace
xtreg milburden year l.ln_gdp c.l.russia_spatial##c.l.russia_land_borderkm l.spatial_spillins l.pv_est l.sl_uem_totl_zs, fe
outreg2 using "nordics/output/nordicsols.xls", ctitle (Full Sample OLS, Milex/GDP) label addtext() bdec(3) cdec(3) pdec(3) tdec(3) rfmt(3) e(r2_o) append

******************************
*Figure 6: Disaggregated Bars*
******************************
#delimit;
preserve;
keep if [year==2014|year==2023] & nato_year_dummy==1&countryname!="Iceland" & countryname !="Montenegro" & countryname!="Macedonia";
graph bar (mean) equipment_gdp (mean) personnel_gdp (mean) operating_gdp (mean) infrastructure_gdp, scheme (economist) 
over (year, label(labcolor(red) angle(ninety) labsize(tiny))) 
over(countryname, label(labcolor(black) 
angle(forty_five) labsize(vsmall))) stack yline(2 .4, lcolor(red) lpattern(dash) lwidth(medthick)) 
ytitle("Expenditures/GDP (%), by category (2014 & 2023)", size(small) margin(medium)) legend(rows(1) position(6)  size(vsmall) 
label (1 "equipment") label (2 "personnel") label (3 "O&M")  label (4 "infrastructure")) ysize (10) ylab(0(.5)4, labsize(vsmall));
graph save nordics\output\Figure6disagg_all.gph, replace;
graph export nordics\figures\Figure6disagg_all.tif, replace;
restore;

#delimit cr;





*******************************************************
*FIGURE 4x: SLOPE CHART, NORDICS, 2015 instead of 2014*
*******************************************************


*Generate 2014 and 2020 equipment and milex*
#delimit cr;
preserve

bysort ccode: gen equipment_gdp_2014=equipment_gdp if year==2014
bysort ccode: gen equipment_gdp_2020=equipment_gdp if year==2020
bysort ccode: gen milburden_2014=milburden if year==2014
bysort ccode: gen milburden_2020=milburden if year==2020

bysort ccode (equipment_gdp_2014): replace equipment_gdp_2014 = equipment_gdp_2014[1]
bysort ccode (equipment_gdp_2020): replace equipment_gdp_2020 = equipment_gdp_2020[1]

bysort ccode (milburden_2014): replace milburden_2014 = milburden_2014[1]
bysort ccode (milburden_2020): replace milburden_2020 = milburden_2020[1]
 
* Checking which value is lower than previous data value
#delimit cr;
 generate negative_equipment = (equipment_gdp_2020 < equipment_gdp_2014)
 generate negative_milburden = (milburden_2020 < milburden_2014)

 
 generate labequipment2014 = countryname + ", " + string((equipment_gdp2014))
 generate labequipment2020 = countryname + ", " + string((equipment_gdp_2020))
 
 generate labmilburden2014 = countryname + ", " + string((milburden2014))
 generate labmilburden2020 = countryname + ", " + string((milburden_2020))
 
 generate country1 = 1
 generate country2 = 2
 
 *plot*
#delimit cr;

 keep if nordic_dummy==1
  colorpalette w3, nograph
 twoway  (pcspike equipment_gdp_2014 country1 equipment_gdp_2020 country2 if negative_equipment == 0, legend(off) lcolor("`r(p11)'")) ///
   (pcspike  equipment_gdp_2014 country1 equipment_gdp_2020 country2 if negative_equipment == 1, legend(off) lcolor("`r(p1)'")) ///
   (scatter equipment_gdp_2014 country1, ms(i) mlabposition(9) mlabel(labequipment2014)) ///
   (scatter equipment_gdp_2020 country2, ms(i) mlabposition(3) mlabel(labequipment2020)) ///
   (scatteri .65 1 "{bf}Year 2014", ms(i) mlabpos(9)) ///
   (scatteri .65 2 "{bf}Year 2020", ms(i) mlabpos(3)) ///   
   , ///
   ylabel(0(.1).6, labsize(2) nogrid) ///
   ytitle("Equipment/GDP", size(2) orient(horizontal)) ///
   yscale(range(0 .6)) ///
   xlabel(1(1)2) ///
   xscale(off) ///
   xtitle("") ///
   xscale(range(.5 1)) ///
   aspect(1.3) ///
   title("{bf}Slope Chart", pos(11) size(2.75)) ///
   subtitle("Equipment/GDP: 2014 Vs. 2020" " ", pos(11) size(2)) ///
   graphregion(margin(r=25)) ///
   scheme(white_w3d)
   graph save nordics/output/figure4a_equipment_slopechart.gph, replace
   graph export nordics/figures/figure4a_equipment_slopechart.tif, replace
   
   
   restore
   
   
   
   *Generate 2008 and 2014 equipment and milex*
#delimit cr;
preserve

bysort ccode: gen equipment_gdp_2008=equipment_gdp if year==2008
bysort ccode: gen equipment_gdp_2015=equipment_gdp if year==2015
bysort ccode: gen milburden_2008=milburden if year==2008
bysort ccode: gen milburden_2015=milburden if year==2015

bysort ccode (equipment_gdp_2008): replace equipment_gdp_2008 = equipment_gdp_2008[1]
bysort ccode (equipment_gdp_2015): replace equipment_gdp_2015 = equipment_gdp_2015[1]

bysort ccode (milburden_2008): replace milburden_2008 = milburden_2008[1]
bysort ccode (milburden_2015): replace milburden_2015 = milburden_2015[1]
 
* Checking which value is lower than previous data value
#delimit cr;
 generate negative_equipment = (equipment_gdp_2015 < equipment_gdp_2008)
 generate negative_milburden = (milburden_2015 < milburden_2008)

 
 generate labequipment2008 = countryname + ", " + string((equipment_gdp_2008))
 generate labequipment2015 = countryname + ", " + string((equipment_gdp_2015))
 
 generate labmilburden2008 = countryname + ", " + string((milburden_2008))
 generate labmilburden2015 = countryname + ", " + string((milburden_2015))
 
 generate country1 = 1
 generate country2 = 2
 
 *plot*
#delimit cr;

 keep if nordic_dummy==1
  colorpalette w3, nograph
 twoway  (pcspike equipment_gdp_2008 country1 equipment_gdp_2015 country2 if negative_equipment == 0, legend(off) lcolor("`r(p11)'")) ///
   (pcspike  equipment_gdp_2008 country1 equipment_gdp_2015 country2 if negative_equipment == 1, legend(off) lcolor("`r(p1)'")) ///
   (scatter equipment_gdp_2008 country1, ms(i) mlabposition(9) mlabel(labequipment2008)) ///
   (scatter equipment_gdp_2015 country2, ms(i) mlabposition(3) mlabel(labequipment2015)) ///
   (scatteri .65 1 "{bf}Year 2008", ms(i) mlabpos(9)) ///
   (scatteri .65 2 "{bf}Year 2015", ms(i) mlabpos(3)) ///   
   , ///
   ylabel(0(.1).6, labsize(2) nogrid) ///
   ytitle("Equipment/GDP", size(2) orient(horizontal)) ///
   yscale(range(0 .6)) ///
   xlabel(1(1)2) ///
   xscale(off) ///
   xtitle("") ///
   xscale(range(.5 1)) ///
   aspect(1.3) ///
   title("{bf}Slope Chart", pos(11) size(2.75)) ///
   subtitle("Equipment/GDP: 2008 Vs. 2015" " ", pos(11) size(2)) ///
   graphregion(margin(r=25)) ///
   scheme(white_w3d)
   graph save nordics/output/figure4b_equipment_slopechart.gph, replace
   graph export nordics/figures/figure4b_equipment_slopechart.tif, replace
   
   
   #delimit;
graph combine nordics/output/figure4a_equipment_slopechart.gph nordics/output/figure4b_equipment_slopechart.gph, 
title("Parallel Trends: Equipment/GDP", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("Nordic States, Pre- and Post-Wales Pledge", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics/output/figure4_paralleltrendsnordicsonly, replace;
graph export nordics/figures/figure4_paralleltrendsnordicsonly.tif, replace;


restore;
   
#delimit cr;

*Figure TBD Scatterfit DID*
#delimit;
scatterfit equipment_gdp ln_gdp  if ccode!=2 & year>=2008, mlab() fit(lfitci) controls() fcontrols() regparameters(coef sig) leginside by(did);
graph save nordics\output\equipment_gdp_scatterfitdid.gph, replace;
scatterfit milburden ln_gdp  if ccode!=2 & year>=2008, mlab() fit(lfitci) controls() fcontrols() regparameters(coef sig) leginside by(did);
graph save nordics\output\milburden_scatterfitdid.gph, replace;

grc1leg nordics\output\equipment_gdp_scatterfitdid.gph nordics\output\milburden_scatterfitdid.gph, 
title("", size(medlarge) margin(medsmall) color(black) position(6))
subtitle("", size(medarge) position(9) orientation(vertical) margin(medsmall) color(black));
graph save nordics\output\scatterfit_did, replace;
graph export nordics\figures\scatterfit_did.tif, replace;
